package com.example.applyforaid.service.impl;

import com.example.applyforaid.entity.ManagerUser;
import com.example.applyforaid.entity.StudentUser;
import com.example.applyforaid.service.IUserVerificationService;

import javax.servlet.http.HttpSession;

public class UserVerificationServiceImpl implements IUserVerificationService {
    @Override
    public int getUserRole(HttpSession session) {
        Object user = session.getAttribute("user");
        if (user == null)
            return -1; //未登录
        else
        {
            if (user instanceof ManagerUser)
                return ((ManagerUser) user).getManagerRole(); //leader Id
            else
            {
                if (user instanceof StudentUser)
                    return 0; //学生
            }
            return -1;
        }
    }

    @Override
    public void removeSession(HttpSession session) {
        session.removeAttribute("user");
    }
}
